package com.example.gbuffer.RenderPass;

import android.opengl.GLES32;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import com.example.gbuffer.Component.Framebuffer.Framebuffer;
import com.example.gbuffer.Utils.GLViewportRect;

public class RenderPass {
    private Framebuffer m_buffer;
    private GLViewportRect m_viewport = new GLViewportRect(0, 800, 800, 600);

    public RenderPass(Framebuffer buffer){
        m_buffer = buffer;
    }

    /**
     * @brief 设置这个渲染流程需要的视口（原点在屏幕左下角，x轴向右，y轴向上）
     * @param rect 描述视口的矩形
     */
    public void setViewport(GLViewportRect rect) {
        m_viewport = rect;
    }

    public void executeDrawCalls(){

        // 绑定需要写入的帧缓冲
        m_buffer.bind();

        // 设置需要绘制的区域（视口）
        GLES32.glViewport(m_viewport.x(), m_viewport.y(), m_viewport.width(), m_viewport.height());

        // 调用 Supplier 函数
        for (Supplier<Integer> supplier : m_suppliers) {
            supplier.get();     // 输出每个 Supplier 的返回值
        }
    }

    protected void addDrawCall(Supplier<Integer> func) {
        m_suppliers.add(func);
    }

    private List<Supplier<Integer>> m_suppliers = new ArrayList<>();
}
